package org.apache.struts.ehr.patient_details.action;

import java.util.Date;
import java.util.Map;

import org.apache.struts.ehr.medical_records.model.HL7Message;
import org.apache.struts.ehr.patient_details.model.PatientDetails;

import com.earogya.communicate.Communicator;
import com.earogya.logic.patient_details.CreateADTA04;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class PatientRegistrationFormAction extends ActionSupport{
	private PatientDetails patientDetails;
	private HL7Message message;
	private Date date;
	private SearchResultsAction action;

	public HL7Message getMessage() {
		return message;
	}

	public PatientDetails getPatientDetails() {
		return patientDetails;
	}

	public void setPatientDetails(PatientDetails patientDetails) {
		this.patientDetails = patientDetails;
	}

	public String execute() throws Exception {
		Map<String, Object> session=ActionContext.getContext().getSession();
		CreateADTA04 createMessage=new CreateADTA04(patientDetails);
		String msg=createMessage.createMessage((String)session.get("facility"));
		message=new HL7Message();
		if(!msg.equals(null)){
			Communicator c=new Communicator();
			String reply=c.sendMessage(msg);
			message.setMessage(msg+"-------------"+reply);
			System.out.print(reply);
			
		}
				else{
			message.setMessage("empty");
		}
		return SUCCESS;
	}
	
	public void validate(){
		
	}
}
